<?
	$valok=true;
	if ($valok&&isset($_REQUEST['submit'])){
		$submit=$_REQUEST['submit'];
	}else{
		echo "submit";
		$valok=false;
	}
	if ($valok&&isset($_REQUEST['pid'])){
		$pid=$_REQUEST['pid'];
	}else{
		echo "pid";
		$valok=false;
	}
	if ($valok&&isset($_REQUEST['lang'])){
		$lang=$_REQUEST['lang'];
	}else{
		echo "lang";
		$valok=false;
	}
	if ($valok&&isset($_REQUEST['src'])){
		$src=$_REQUEST['src'];
	}else{
		$valok=false;
	}
	if ($valok){
		require_once('../db/dbinfo.php');
		$sql="select rid from status order by rid desc limit 1";
		$ret = mysqli_query($dbc,$sql);
		$num=mysqli_num_rows($ret);
		if ($num==0){
			$maxid=0;
		}else{
			$row=mysqli_fetch_array($ret,MYSQLI_ASSOC);
			$maxid = $row['rid'];
			$maxid+=1;
		}
		$len = (strlen($src)/1024);
		$slen = number_format($len,2,'.',',')."KB";		
		$sql="insert into status set rid='$maxid' ,pid='$pid' ,src='$src' , res='Waiting',lang='$lang',subtime=now(),codelen='$slen'";
		mysqli_query($dbc,$sql);
		$isin=mysqli_affected_rows($dbc);
		if ($isin==0){
			echo "<h1>insert into db error</h1>";
		}
		$host="localhost";
		$port=5566;
		$fp = fsockopen($host,$port,$errno,$errstr);
		if (!$fp){
			echo "<h1>socket error</h1>";
			exit;
		}else{
			$msg="submit\n";
			if (fwrite($fp,$msg)===false){
				echo "<h1>file error</h1>";
				exit;
			}
			fclose($fp);
			Header("Location:status.php");
		}		
		
		//echo "ok";
		exit;
	}else{
		echo "debug";
	}
?>	
